<template>
    <div class="app-detail">
        <el-card class="box-card">
            <div class="container-header">
                <div class="hign-line"></div>
                <div class="header-left">
                    {{$t('inventoryManagement.baseInfo')}}
                </div>
            </div>
            <el-form :model="viewModel" ref="additonForm" v-show="showSearch" label-width="108px">
                <el-row :gutter="24" class="mb8">
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.sapBatch')" prop="inspectionLotMark">
                            <el-input v-model="viewModel.inspectionLotMark" clearable disabled size="small" />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="6">
                        <el-form-item label="MSL等级" prop="materialMsl">
                            <el-input v-model="viewModel.materialMsl" disabled clearable size="small" />
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.materialName')" prop="materialName">
                            <el-input v-model="viewModel.materialName" clearable disabled size="small" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.materialNo')" prop="materialCode">
                            <el-input v-model="viewModel.materialCode" clearable disabled size="small" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.lichn')" prop="lichn">
                            <el-input v-model="viewModel.lichn" clearable disabled size="small" />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="6">
                        <el-form-item label="规格型号" prop="specificationsModels">
                            <el-input v-model="viewModel.specificationsModels" clearable disabled size="small" />
                        </el-form-item>
                    </el-col> -->
                    <!-- <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.materialType')" prop="materialType">
                            <el-input v-model="viewModel.materialType" disabled size="small" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="物料小类" prop="materialMin">
                            <el-input v-model="viewModel.materialMin" disabled size="small" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.maturity')" prop="maturity">
                            <el-input v-model="viewModel.maturity" disabled clearable size="small" />
                        </el-form-item>
                    </el-col> -->
                    <!-- <el-col :span="6">
                        <el-form-item label="【SAP】成熟度" prop="sapMaturity">
                            <el-input v-model="viewModel.sapMaturity" disabled size="small" />
                        </el-form-item>
                    </el-col> -->

                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.supplierNo')" prop="supplierCode">
                            <el-input v-model="viewModel.supplierCode" disabled clearable size="small" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.oldBatchQuantity')" prop="batchAmount">
                            <el-input disabled v-model="viewModel.batchAmount" clearable size="small" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.oldUnit')" prop="mengeneinh">
                            <el-input v-model="viewModel.mengeneinh" clearable disabled size="small" />
                        </el-form-item>
                    </el-col>
                    <!--                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.isTestMaterial')" prop="experimentMaterial">
                            <span class="labelN" v-if="viewModel.experimentMaterial !== '1'">{{$t('public.no')}}</span>
                            <span class="labelY" v-if="viewModel.experimentMaterial === '1'">{{$t('public.yes')}}</span>
                        </el-form-item>
                    </el-col>-->
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.factory')" prop="factoryName">
                            <el-input v-model="viewModel.factoryName" disabled clearable size="small" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.reversionUnit')" prop="amendMeng">
                            <el-input v-model="viewModel.amendMeng" disabled clearable size="small" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.reversionBatchQuantity')" prop="amendBatch">
                            <el-input v-model="viewModel.amendBatch" disabled clearable size="small" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.inspectionPlanVersion')" prop="version">
                            <el-input v-model="viewModel.version" disabled clearable size="small" />
                        </el-form-item>
                    </el-col>
                    <!--                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.outerPackaging')" prop="outerPacking">
                            <el-select v-model="viewModel.outerPacking" disabled :placeholder="$t('public.select_holder',{select_holder: $t('inspectionManagement.outerPackaging')})" style="width:100%;" clearable size="small">
                                <el-option key="0" label="OK" value="0" />
                                <el-option key="1" label="NG" value="1" />
                                <el-option key="2" label="NA" value="2" />
                            </el-select>
                        </el-form-item>
                    </el-col>-->
                    <el-col :span="6">
                        <el-form-item :label="$t('inventoryManagement.skipBatchExemptionFromInspection')" prop="exempted">
                            <div class="labelN" v-if="viewModel.exempted !== '1'&&viewModel.exempted !== '2'">{{$t('public.no')}}</div>
                            <div class="labelY" v-if="viewModel.exempted === '1'">{{$t('public.yes')}}</div>
                            <span class="labelB" v-if="viewModel.exempted === '2'">审批中</span>
                        </el-form-item>
                    </el-col>
                  <el-col :span="6">
                    <el-form-item :label="$t('inspectionManagement.COA')" prop="inspectionCoa">
                      <el-select v-model="viewModel.inspectionCoa" style="width:100%;" disabled size="small">
                        <el-option key="0" label="OK" value="0" />
                        <el-option key="1" label="NG" value="1" />
                        <el-option key="NA" label="NA" value="2" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item :label="'供应商名称'" prop="supplierName">
                        <el-input v-model="viewModel.supplierName" disabled clearable size="small" />
                    </el-form-item>
                  </el-col><el-col :span="6">
                    <el-form-item :label="'供应商名称（修改后）'" prop="supplierAliasName">
                        <el-input v-model="viewModel.supplierAliasName" disabled clearable size="small" />
                    </el-form-item>
                  </el-col>
                </el-row>

            </el-form>
        </el-card>
        <!-- 关联条码表 -->
        <el-button @click="showglb" style="margin-top: 14px;">{{$t('inspectionManage.barcode')}}</el-button>
        <el-card class="box-card" id="fullscreen" style="margin-top:24px;">
            <div class="app-container">
                <div class="container-header">
                    <div class="hign-line"></div>
                    <div class="header-left">
                        {{$t('inventoryManagement.inspectionInfo')}}
                    </div>
                    <div class="header-right">
                        <i class="s-icon" :class="{
            'el-icon-full-screen': !fullscreen,
            'el-icon-copy-document': fullscreen,
          }" @click="changeFull"></i>
                    </div>
                </div>
                <el-row :gutter="10" class="mb8">
                </el-row>
                <div class="container-table">
                    <el-table :height="tableHeight" border stripe v-loading="loading" :data="typeList" @selection-change="handleSelectionChange">
                        <el-table-column :label="$t('inventoryManagement.specialCharacteristics')" align="left" prop="symbol" minWidth="80" :show-overflow-tooltip="true">
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.inspectionItems')" align="left" prop="projectName" minWidth="160" />
                        <el-table-column :label="$t('inventoryManagement.code')" align="left" prop="projectCode" minWidth="120" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.inspectionTypeUnit')" prop="unitName" minWidth="130" align="left" :show-overflow-tooltip="true" />

                        <el-table-column :label="$t('inventoryManagement.inspectionType')" minWidth="130" align="left" prop="checkoutTypeCopy"> </el-table-column>

                        <el-table-column :label="$t('inventoryManagement.targetValue')" align="left" prop="targetValue" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.lowerValue')" align="left" prop="lowerLimit" :show-overflow-tooltip="true">
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.upperValue')" align="center" prop="upperLimit">
                        </el-table-column>
                        <!-- <el-table-column :label="$t('inventoryManagement.resultValue')" align="center" prop="resultValue">
                            <el-table-column :label="item" v-for="(item,index) in tableHeader" :key="index" minWidth="110" align="center" :show-overflow-tooltip="true">
                                <template slot-scope="scope">
                                    <span>{{scope.row.resultValue ?scope.row.resultValue.split(',')[index]:''}}</span>
                                </template>
                            </el-table-column>
                        </el-table-column> -->
                        <el-table-column :label="$t('inventoryManagement.frequency')" minWidth="110" align="left" prop="itemFrequency" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.frequencyValue')" align="left" prop="itemFrequencyValue" :show-overflow-tooltip="true"></el-table-column>
                        <el-table-column :label="$t('inspectionManagement.SampleSizeCode')" align="left" prop="sampleCode" minWidth="120" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inspectionManagement.ReceivedQuantity')" align="left" prop="samAc" minWidth="120" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inspectionManagement.RejectionNumber')" align="left" prop="samRe" minWidth="120" :show-overflow-tooltip="true" />
                        <!-- <el-table-column label="SN编号" align="left" prop="snNums" minWidth="120" :show-overflow-tooltip="true" /> -->
                        <el-table-column :label="$t('inventoryManagement.decimalPlaces')" prop="decimalPlace" :show-overflow-tooltip="true"> </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.samplingScheme')" align="left" prop="samplingOne" minWidth="140" :show-overflow-tooltip="true">
                        </el-table-column>
                        <el-table-column :label="'缺陷等级'" align="left" prop="flawLevel" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.samplingQuantity')" align="left" prop="samplingAmount" :show-overflow-tooltip="true">
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.qualifiedQuantity')" align="left" prop="qualifiedNum" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.testMethod')" align="left" prop="detectionOne" :minWidth="200" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>{{scope.row.detectionOne}}</span> <span>{{scope.row.detectionTwo}}</span>
                            </template>
                        </el-table-column>
                        <!-- <el-table-column :label="$t('inventoryManagement.gapValue')" minWidth="110" align="left" prop="gap" :show-overflow-tooltip="true">
                        </el-table-column> -->
                        <el-table-column :label="$t('inventoryManagement.inspector')" minWidth="110" align="left" prop="inspectorName" :show-overflow-tooltip="true"></el-table-column>
                        <!-- <el-table-column :label="$t('inventoryManagement.inspectionValue')" align="center" :show-overflow-tooltip="true">
                            <el-table-column :label="item" v-for="(item,index) in tableHeader" :key="index" minWidth="110" align="center" :show-overflow-tooltip="true">
                                <template slot-scope="scope">
                                    <span>{{scope.row.checkoutValue ?scope.row.checkoutValue.split(',')[index]:''}}</span>
                                </template>
                            </el-table-column>
                        </el-table-column> -->
                        <el-table-column :label="$t('defectIncoming.smallDefect')" minWidth="110" align="left" prop="flawProjectName" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('public.remark')" align="left" prop="classRemark" :minWidth="150" :show-overflow-tooltip="true" />

                        <el-table-column :label="$t('inspectionManagement.checkoutResult')" align="center" width="100">
                            <template slot-scope="scope">
                                <div>
                                    <span v-if="scope.row.checkoutResult===0" class="result-tag-red">不合格</span>
                                    <span v-else-if="scope.row.checkoutResult===1" class="result-tag-green">合格</span>
                                    <span v-else-if="scope.row.checkoutResult===2" class="result-tag-yellow">NA</span>
                                    <span v-else class="labelN">未录入</span>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('public.opera')" align="center" width="100">
                            <template slot-scope="scope">
                                <div class="action-wrap">
                                    <table-body-btn type="gwview" :name="$t('home.view')" @click.native="handleEdit(scope)" />
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-drawer :with-header="false" :visible.sync="drawer" :title="$t('inspectionManagement.editInspectionItems')" size="50%" :direction="direction" :before-close="handleClose">
                        <div class="app-container" style="max-height:calc(100vh - 160px);overflow-y:auto">
                            <div class="container-header">
                                <div class="header-left">
                                    {{$t('inspectionManagement.editInspectionItems')}}
                                </div>
                            </div>
                            <el-form :model="currentItem" ref="currentQueryForm" v-show="showSearch" label-width="88px">
                                <el-row :gutter="24" class="mb8">
                                    <el-col :span="8">
                                        <el-form-item :label="$t('inventoryManagement.inspectionItems')" prop="projectName">
                                            <el-input v-model="currentItem.projectName" readonly clearable size="small" @keyup.enter.native="handleQuery" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item :label="$t('inventoryManagement.inspectionType')" prop="checkoutTypeCopy">
                                            <el-input v-model="currentItem.checkoutTypeCopy" readonly clearable size="small" @keyup.enter.native="handleQuery" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item :label="$t('inventoryManagement.samplingQuantity')" prop="samplingAmount">
                                            <el-input v-model="currentItem.samplingAmount" readonly clearable size="small" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" v-if="currentItem.samplingOne==='GB/T2828.1-2012'&&currentItem.checkoutType==='布尔型'">
                                        <el-form-item :label="$t('inspectionManagement.SampleSizeCode')" prop="sampleCode">
                                            <el-input v-model="currentItem.sampleCode" readonly clearable size="small" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" v-else>
                                        <el-form-item :label="$t('inventoryManagement.upperValue')" prop="upperLimit">
                                            <el-input v-model="currentItem.upperLimit" readonly clearable size="small" >
                                                <template slot="append">
                                                    {{currentItem.upperLimitContains==='0'?"不包含":"包含"}}
                                                </template>
                                            </el-input> 
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" v-if="(currentItem.samplingOne==='GB/T2828.1-2012'||currentItem.samplingOne==='GB/T2828.2-2008')&&currentItem.checkoutType==='布尔型'">
                                        <el-form-item :label="$t('inspectionManagement.ReceivedQuantity')" prop="samAc">
                                            <el-input v-model="currentItem.samAc" readonly clearable size="small" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" v-else>
                                        <el-form-item :label="$t('inventoryManagement.lowerValue')" prop="lowerLimit">
                                            <el-input v-model="currentItem.lowerLimit" readonly clearable size="small" >
                                                <template slot="append">
                                                    {{currentItem.lowerLimitContains==='0'?"不包含":"包含"}}
                                                </template>
                                            </el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" v-if="currentItem.samplingOne==='GB/T2828.1-2012'&&currentItem.checkoutType==='布尔型'">
                                        <el-form-item :label="$t('inspectionManagement.RejectionNumber')" prop="samRe">
                                            <el-input v-model="currentItem.samRe" readonly clearable size="small" />
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="8">
                                        <el-form-item :label="$t('inventoryManagement.inspector')" prop="inspectorName">
                                            <el-input v-model="currentItem.inspectorName" readonly clearable size="small" />
                                            <!-- <select-user-dialog v-model="currentItem.inspectorName" :placeholder="$t('public.select_holder',{select_holder: $t('inventoryManagement.inspector')})" :titleName="$t('defectIncoming.selectMan')" @callback="(id)=>userDataCallback(id)" /> -->
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" v-if="currentItem.checkoutType!=='布尔型'">
                                        <el-form-item :label="$t('inventoryManagement.targetValue')" prop="targetValue">
                                            <el-input v-model="currentItem.targetValue" readonly size="small" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24" v-if="currentItem.checkoutType==='布尔型'">
                                        <el-form-item :label="$t('inventoryManagement.targetValue')" prop="targetValue">
                                            <el-input v-model="currentItem.targetValue" resize="none" readonly type="textarea" :rows="3" size="small" />
                                        </el-form-item>
                                    </el-col>
                                    <template v-if="currentItem.checkoutType==='数值'">
                                    <el-col :span="8" >
                                        <el-form-item :label="$t('outlier.min')" prop="minimum">
                                            <el-input v-model="currentItem.minimum" readonly clearable size="small" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" >
                                        <el-form-item :label="$t('outlier.max')" prop="maximum">
                                            <el-input v-model="currentItem.maximum" readonly clearable size="small" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" >
                                        <el-form-item :label="$t('outlier.averageValue')" prop="meanValue">
                                            <el-input v-model="currentItem.meanValue" readonly clearable size="small" />
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8" >
                                        <el-form-item :label="$t('outlier.range')" prop="rangeValue">
                                            <el-input v-model="currentItem.rangeValue" readonly clearable size="small" />
                                        </el-form-item>
                                    </el-col>
                                    </template>
                                    <el-col :span="24">
                                        <el-form-item label=" ">
                                            <template v-if="currentItem.checkoutType==='数值'">
                                                <el-row  :gutter="24" class="mb8" v-for="(itemT,indexT) in displayedCheckoutList" :key="indexT">
                                                    <el-col :span="8">
                                                        <el-form-item :label="$t('specimen.sampleCode')" label-width="60px">{{ itemT.sampleCode }} </el-form-item>
                                                    </el-col>
                                                    <el-col :span="20">
                                                        <el-table border stripe :data="itemT.checkoutItemList" max-height="300">
                                                            <el-table-column type="index" width="55" align="center"></el-table-column>
                                                            <el-table-column :label="$t('inventoryManagement.inspectionValue')" align="left" prop="checkoutValue" />
                                                            <!-- <el-table-column :label="$t('inspectionManagement.checkoutResult')" align="left" prop="resultValue"></el-table-column> -->
                                                            <el-table-column :label="$t('inventoryManagement.judgmentResult')" align="left" prop="result">
                                                                <template slot-scope="scope">
                                                                <div v-show="scope.row.resultValue">
                                                                    <span v-if="scope.row.result=='0'" class="result-tag-red">不合格</span>
                                                                    <span v-if="scope.row.result=='1'" class="result-tag-green">合格</span>
                                                                    <span v-if="scope.row.result=='2'" class="result-tag-yellow">NA</span>
                                                                </div>
                                                                </template>
                                                            </el-table-column>
                                                        </el-table>
                                                    </el-col>
                                                </el-row>
                                              <!-- 滚动到底部加载更多按钮 -->
                                              <div ref="loadMore" v-if="hasMore" class="load-more-container">
                                                <button v-if="!loadMoreLoading" @click="loadMore">加载更多</button>
                                                <button v-else>加载中...</button><!--v-else-->
                                              </div>
                                            </template>
                                            <el-table border stripe v-loading="loading" :data="currentItem.inspectionValues" max-height="300" v-else>
                                                <el-table-column type="index" width="55" align="center"></el-table-column>
                                                <el-table-column label="合格数" align="left" prop="inspectionValue" v-if="(currentItem.samplingOne==='GB/T2828.1-2012'||currentItem.samplingOne==='GB/T2828.2-2008')&&currentItem.checkoutType==='布尔型'">
                                                    <template slot-scope="scope">
                                                        <div>
                                                            <el-input v-model="scope.row.inspectionValue" disabled :class="'input'+scope.$index" type="number" @input="(e)=>acceptChange(e,scope)" clearable size="small" />
                                                        </div>

                                                    </template>
                                                </el-table-column>
                                                <el-table-column :label="$t('inventoryManagement.inspectionValue')" align="left" prop="inspectionValue" v-else>
                                                    <template slot-scope="scope">
                                                        <div>
                                                            <el-select disabled transfer :popper-append-to-body="false" v-if="currentItem.checkoutType==='布尔型'" @change="(e)=>changeCheckoutValue(e,scope)" v-model="scope.row.inspectionValue" style="width:100%;" clearable size="small">
                                                                <el-option key="0" label="OK" value="OK" />
                                                                <el-option key="1" label="NG" value="NG" />
                                                                <el-option key="2" label="NA" value="NA" />
                                                            </el-select>
                                                            <el-input readonly v-else v-model="scope.row.inspectionValue" :class="'input'+scope.$index" type="number" @input="(e)=>valueChange(e,scope)" @keyup.enter.native="nextInput('input'+(scope.$index+1),scope.$index)" clearable size="small" />
                                                        </div>

                                                    </template>
                                                </el-table-column>
                                                <el-table-column :label="((currentItem.samplingOne==='GB/T2828.1-2012'||currentItem.samplingOne==='GB/T2828.2-2008')&&currentItem.checkoutType==='布尔型')?'不合格数':$t('inventoryManagement.resultValue')" align="left" prop="resultValue" :show-overflow-tooltip="true" />
                                                <el-table-column :label="$t('inventoryManagement.judgmentResult')" align="left" :show-overflow-tooltip="true">
                                                    <template slot-scope="scope">
                                                        <div  v-show="scope.row.resultValue == '0' || scope.row.resultValue">
                                                            <span v-if="scope.row.resultType===0" class="result-tag-red">不合格</span>
                                                            <span v-if="scope.row.resultType===1" class="result-tag-green">合格</span>
                                                        </div>
                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item :label="$t('defectIncoming.inspectResults')" v-show="comprehensiveResults!==''">
                                            <span :class="comprehensiveResults==='不合格'?'result-tag-red':comprehensiveResults==='NA'?'result-tag-yellow':'result-tag-green'">{{comprehensiveResults}}</span>
                                        </el-form-item>
                                    </el-col>

                                    <el-col :span="24" v-if="comprehensiveResults==='不合格'">

                                        <el-form-item :label="$t('defectIncoming.smallDefect')">
                                            <el-table border stripe v-loading="loading" :data="currentItem.flawList" max-height="300">
                                                <el-table-column type="index" width="55" align="center"></el-table-column>

                                                <el-table-column :label="$t('defectIncoming.minFlawName')" align="left" prop="minFlawName">
                                                    <template slot-scope="scope">
                                                        <div>
                                                            <el-select disabled transfer :popper-append-to-body="false" filterable v-model="scope.row.minFlawName" style="width:100%;" clearable size="small">
                                                                <el-option v-for="item in minFlawOptions" @click.native="changeFlaw(item,scope)" :key="item.id" :label="item.minFlawName" :value="item.minFlawName" />
                                                            </el-select>
                                                        </div>

                                                    </template>
                                                </el-table-column>
                                                <el-table-column :label="$t('defectIncoming.minFlawNr')" align="left" prop="minFlawNr">
                                                    <template slot-scope="scope">
                                                        <div>
                                                            <el-input disabled v-model="scope.row.minFlawNr" type="number" clearable size="small" />
                                                        </div>

                                                    </template>
                                                </el-table-column>
                                            </el-table>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item :label="$t('public.upload')">
                                            <file-upload ref="projectItemFiles" bizType='UPLOAD_FILE_ITEM' disabled :otherList="itemFileList" :bizId="rowId" @change="(fileList)=>itemFileChange(fileList)"></file-upload>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="24">
                                        <el-form-item :label="$t('public.remark')">
                                            <el-input v-model="currentItem.classRemark" readonly resize="none" type="textarea" :rows="3" size="small" />
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                            </el-form>
                        </div>
                        <div class="drawer-footer">
                            <el-button icon="el-icon-close" size="mini" @click="drawerClose" class="drawer-close">关闭</el-button>
                        </div>
                    </el-drawer>
                </div>
            </div>
        </el-card>
        <el-card class="box-card" style="margin-top:14px">
            <div class="container-header">
                <div class="hign-line"></div>
                <div class="header-left">
                    缺陷判定
                </div>
            </div>
            <div class="container-table">
                    <el-table ref="flowTable" :row-class-name="tableRowClassNameDefect" :data="inspectionFlawList" :border='true'>
                        <el-table-column :label="'项目类型'" prop="projectType" :show-overflow-tooltip="true" />
                        <!-- <el-table-column :label="'缺陷类型'" prop="flawLevel" minWidth="80" :show-overflow-tooltip="true" /> -->
                        <!-- <el-table-column :label="'抽样方案'" prop="samplingOne" minWidth="110" /> -->
                        <el-table-column :label="'抽样方案'" minWidth="180" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>{{ scope.row.samplingOne }}</span><span :style='{marginLeft:"12px"}'>{{scope.row.samplingTwo}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="'CR允收'" prop="samplingThreeCr" minWidth="90" />
                        <el-table-column :label="'AC/RE'" minWidth="90" :show-overflow-tooltip="true">
                            <template slot-scope="scope" v-if="scope.row.samReCr">
                                <span>{{ scope.row.samAcCr }}</span><span>/</span><span>{{scope.row.samReCr}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="'MA允收'" prop="samplingThreeMa" minWidth="90" />
                        <el-table-column :label="'AC/RE'" minWidth="90" :show-overflow-tooltip="true">
                            <template slot-scope="scope" v-if='scope.row.samReMa'>
                                <span>{{ scope.row.samAcMa }}</span><span>/</span><span>{{scope.row.samReMa}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="'MI允收'" prop="samplingThreeMi" minWidth="90" />
                        <el-table-column :label="'AC/RE'" minWidth="90" :show-overflow-tooltip="true">
                            <template slot-scope="scope" v-if="scope.row.samReMi">
                                <span>{{ scope.row.samAcMi }}</span><span>/</span><span>{{scope.row.samReMi}}</span>
                            </template>
                        </el-table-column>
                        <!-- <el-table-column :label="'检验水平'" minWidth="100" prop="samplingTwo" :show-overflow-tooltip="true" /> -->
                        <!-- <el-table-column :label="'检验等级'" prop="samplingThree" :show-overflow-tooltip="true" /> -->
                        <!-- <el-table-column :label="'设定标准'" minWidth="120" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>Ac：</span><span>{{scope.row.samAc}}</span><span>Re：</span><span>{{scope.row.samRe}}</span>
                            </template>
                        </el-table-column> -->
                        <!-- <el-table-column :label="'统计结果值'" minWidth="120" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>Ac：</span><span>{{Obj[scope.row.id].samAcCount}}</span><span>Re：</span><span>{{Obj[scope.row.id].samReCount}}</span>
                            </template>
                        </el-table-column> -->
                        <el-table-column :label="'CR'" minWidth="120" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span :style="{color:Obj[scope.row.id].samReCountCr >= scope.row.samReCr ? 'red' : '' }">{{Obj[scope.row.id].samReCountCr}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="'MA'" minWidth="120" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span :style="{color:Obj[scope.row.id].samReCountMa >= scope.row.samReMa ? 'red' : '' }">{{Obj[scope.row.id].samReCountMa}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="'MI'" minWidth="120" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span :style="{color:Obj[scope.row.id].samReCountMi >= scope.row.samReMi ? 'red' : '' }">{{Obj[scope.row.id].samReCountMi}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="'判定结果'" minWidth="120" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span v-if='getDefectStatus(scope.row,"no")' style='color:red'>不合格</span>
                                <span v-if='getDefectStatus(scope.row,"yes")' style='color:green'>合格</span>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
        </el-card>
        <el-card class="box-card" style="margin-top:24px">
            <div class="container-header">
                <div class="hign-line"></div>
                <div class="header-left">
                    {{$t('inspectionManagement.comprehensiveJudgment')}}
                </div>
            </div>
            <el-form :model="viewModel" ref="queryForm" v-show="showSearch" label-width="100px">
                <el-row :gutter="24" class="mb8">
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.destructiveMaterialInformation')" prop="destroyAmount">
                            <el-input disabled v-model="viewModel.destroyAmount" clearable size="small" @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item :label="$t('inspectionManagement.judgmentResult')" prop="judgmentResult">
                            <span v-if="viewModel.decideResult==='0'" class="result-tag-red">不合格</span>
                            <span v-else-if="viewModel.decideResult==='1'" class="result-tag-green">合格</span>
                            <span v-else class="result-tag-yellow">暂无判定结果</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24" class="mb8">
 <!-- 试投需求改变，注释，暂时不删除
                    <el-col :span="6" v-if="viewModel.decideResult=='1' && viewModel.inspectionCoa!=1">
                        <el-form-item :label="$t('inspectionManagement.whetherTrial')" prop="returnAmount">
                            <el-select     v-model="viewModel.whetherTrial" style="width: 100%;" disabled
                            clearable size="small" :placeholder="$t('public.select_holder', {select_holder: $t('inspectionManagement.whetherTrial'),})">
                                <el-option v-for="item in isTrialInvestList" :key="item.value"
                                    :label="item.label"  :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-if="viewModel.whetherTrial=='1'">
                        <el-form-item label="假设一次试投不通过是否发起二次试投" prop="twiceTrial">
                            <el-select v-model="viewModel.twiceTrial" style="width: 100%;" disabled
                            clearable size="small" placeholder="请选择">
                                <el-option v-for="item in isTrialInvestList" :key="item.value"
                                    :label="item.label"  :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                -->
                    <el-col :span="12" >
                        <el-form-item :label="$t('inspectionManagement.COAReportPhotoUpload')"  >
                          <file-upload v-model="viewModel.coaBizType" :otherList="coaBizTypeList"  :bizType="'IncomingCoaBizType'"
                          disabled   :bizId="isReuse === 1 ? JSON.parse(viewModel.coaPic).inspectionId:id" @change="(fileList)=>incomingFileChange3(fileList)"></file-upload>
                        </el-form-item>
                    </el-col>

                    <!-- 试投需求改变，注释，暂时不删除
                         <el-col :span="12" v-if="viewModel.whetherTrial=='1'">
                        <el-form-item label="试投材料附件" prop="trialBizType">
                            <file-upload v-model="viewModel.trialBizType" :otherList="trialBizTypeList"  :bizType="'onceTrialDoc'"
                            :bizId="id" @change="(fileList)=>incomingFileChange2(fileList)" disabled></file-upload>
                        </el-form-item>
                    </el-col>
                 -->

                    <el-col :span="24">
                        <el-form-item :label="$t('inventoryManagement.description')" prop="description" style="width:100%;margin-top: 20px;">
                            <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 6}" disabled v-model="viewModel.description" maxlength="1000">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item :label="$t('inventoryManagement.uploadAttachments')" prop="uploadAttachments" style="width:100%">
                            <file-upload v-model="viewModel.uploadAttachments" :otherList="otherList" ref="incomingFiles" :bizId="isReuse === 1 ? JSON.parse(viewModel.coaPic).inspectionId:id"
                            @change="(fileList)=>incomingFileChange(fileList)" disabled></file-upload>
                        </el-form-item>
                    </el-col>

                </el-row>

            </el-form>
        </el-card>
        <div class="submit-footer">
            <el-button icon="el-icon-close" size="small" @click="closeTab" class="drawer-close">{{$t('public.close')}}</el-button>
        </div>
        <template-dialog :visible.sync="templateVisible" />
        <ScanListDialog :visible.sync="scanVisble" :incomingId="id"/>
    </div>

</template>

<script>
import {getType, refreshCache,} from '@/api/basic/dict/type'
import {getNoticeList} from '@/api/system/message'
import FileUploadInput from '@/components/FileUploadInput'
import SupplierDialog from '@/views/components/SupplierDialog'
import MaterialDialog from '@/views/components/MaterialDialog'
import TemplateDialog from '@/views/components/TemplateDialog'
import MeasuringToolDialog from '@/views/components/MeasuringToolDialog'
import {geFileByBiz} from '@/api/file/file'
import {getCollection, incomingInfo,} from '@/api/inspectionManagement/inspectionManagement'
import {listProject} from '@/api/basic/project'
import {listCheckoutUnit} from '@/api/basic/checkoutUnit'
import SelectUserDialog from '@/views/components/SelectUserDialog'
import { BizTypeEnum } from '@/enums/bizTypeEnum'
import ScanListDialog from '@/views/components/ScanListDialog'
class CheckoutItem {
    "id" = void 0 // 主键
    "checkoutValue"= void 0 // 检验值（合格数）
    "classId"= void 0  // 检验项的主键id
    "result"= void 0 // 判定结果
    "resultValue"= void 0 // 结果值（不合格数）
    "sampleCode"= void 0 // 样本编号
    constructor(id,classId,checkoutValue,resultValue,result,sampleCode){
        this.id = id
        this.classId = classId
        this.checkoutValue = checkoutValue
        this.resultValue = resultValue
        this.result = result
        this.sampleCode = sampleCode
    }
}

export default {
    name: 'incomingDetail',
    dicts: ['sys_normal_disable','NYIQC_CE_CLASS'],
    props: ['rowId'],
    components: {
        FileUploadInput,
        SupplierDialog,
        MaterialDialog,
        TemplateDialog,
        MeasuringToolDialog,
        SelectUserDialog,
        ScanListDialog
    },
    data() {
        return {
          checkoutList: [], // 所有检验项数据
          displayedCheckoutList: [], // 当前展示的检验项数据
          loadMoreLoading: false, // 是否正在加载数据
          page: 1, // 当前页数
          pageSize: 200, // 每页条数
          hasMore: true, // 是否还有更多数据
            comprehensiveResults: '',
            direction: 'rtl',
            otherList: [],
            coaFileList: [],
            addInspectionExemption: false,
            minFlawOptions: [],
            currentItem: {},
            templateVisible: false,
            drawer: false,
            approvalOpen: false,
            viewInspectionExemption: false,
            projectList: [],
            unitList: [],
            inspectionOptions: [
                {
                    value: '1',
                    label: '检验项1',
                },
                {
                    value: '2',
                    label: '检验项2',
                },
            ],
            inspectionTypeUnitOptions: [
                {
                    value: '1',
                    label: '单位1',
                },
                {
                    value: '2',
                    label: '单位2',
                },
            ],
            frequencyOptions: [
                {
                    value: '批',
                    label: '批',
                },
                {
                    value: '件',
                    label: '件',
                },
                {
                    value: '年',
                    label: '年',
                },
                {
                    value: '季',
                    label: '季',
                },
                {
                    value: '月',
                    label: '月',
                },
                {
                    value: '日',
                    label: '日',
                },
            ],
            samplingSchemeOptions: [
                {
                    value: '1',
                    label: 'GB/T2828.1-2012',
                },
                {
                    value: '2',
                    label: '百分比',
                },
                {
                    value: '3',
                    label: '固定抽样',
                },
                {
                    value: '4',
                    label: 'C=0',
                },
            ],
            testMethodOptions: [
                {
                    value: '1',
                    label: '目测',
                },
                {
                    value: '2',
                    label: '量具',
                },
                {
                    value: '3',
                    label: '验证',
                },
            ],
            samplingLevelOptions: [
                {
                    value: 'S-1',
                    label: 'S-1',
                },
                {
                    value: 'S-2',
                    label: 'S-2',
                },
                {
                    value: 'S-3',
                    label: 'S-3',
                },
                {
                    value: 'S-4',
                    label: 'S-4',
                },
                {
                    value: 'Ⅰ',
                    label: 'Ⅰ',
                },
                {
                    value: 'Ⅱ',
                    label: 'Ⅱ',
                },
                {
                    value: 'Ⅲ',
                    label: 'Ⅲ',
                },
            ],
            samplingLevelTypeOptions: [
                {
                    value: '正常',
                    label: '正常',
                },
                {
                    value: '放宽',
                    label: '放宽',
                },
                {
                    value: '加严',
                    label: '加严',
                },
            ],
            samplingFixedTypeOptions: [
                {
                    value: '批',
                    label: '批',
                },
                {
                    value: '件',
                    label: '件',
                },
            ],
            pecialCharacteristicsOptions: [
                {
                    value: '空',
                    label: '空',
                },
                {
                    value: 'CC',
                    label: 'CC',
                },
                {
                    value: 'SC',
                    label: 'SC',
                },
            ],
            addModel: {},
            viewModel: {
                lichn: '',
                lot: '',
                materialName: '',
                materialCode: '',
                maturity: '',
                supplierCode: '',
                batchAmount: '',
                mengeneinh: '',
                exempted: '',
                factoryName: '',
                amendMeng: '',
                amendBatch: '',
                outerPacking: '',
                inspectionRohs: '',
                inspectionCoa: '',
            },
            editModel: {},
            approvalForm: {
                status: '1',
                textarea: '',
            },
            selBtn: 1,
            isReuse: 0,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 字典表格数据
            typeList: [],
            tableHeader: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            tableHeight: '350',
            samplingAmount: 0,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                noticeTitle: undefined,
                noticeType: undefined,
                hasRead: undefined,
                createTime: undefined,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                materialName: [
                    {
                        required: true,
                        message: this.$t('formValidation.materialNameCannotBeEmpty'),
                        trigger: 'blur',
                    },
                ],
                materialNo: [
                    {
                        required: true,
                        message: '物料编号不能为空',
                        trigger: 'blur',
                    },
                ],
                supplierNo: [
                    {
                        required: true,
                        message: '供应商编号不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            fullscreen: false,
            itemFileList: [],
            isTrialInvestList: [
                {
                    label: '是',
                    value: '1'
                },
                {
                    label: '否',
                    value: '0'
                }
            ],
            scanVisble:false,
            coaBizTypeList:[],
            inspectionFlawList:[],
            Obj:{}
        }
    },
    computed: {
        id() {
            return this.$route.params.id || this.rowId
        },
        getDefectStatus(){
            let that = this
            // console.log(type,'1111111111111')
            return function(item,type){
                console.log('检查是否更新',item,type)
                if(type == 'no'){
                    if(item.samReCr && that.Obj[item.id].samReCountCr >= item.samReCr){
                        return true
                    }else if(item.samReMa && that.Obj[item.id].samReCountMa >= item.samReMa){
                        return true
                    }else if(item.samReMi && that.Obj[item.id].samReCountMi >= item.samReMi){
                        return true
                    }else return false
                }else if(type == 'yes'){
                    let tempObj = {}
                    let keyObj = {}
                        if(item.samReCr){
                            tempObj.samReCr = item.samReCr
                            keyObj.samReCr = that.Obj[item.id].samReCountCr
                        }
                        if(item.samReMa){
                            tempObj.samReMa = item.samReMa
                            keyObj.samReMa = that.Obj[item.id].samReCountMa
                        }
                        if(item.samReMi){
                            tempObj.samReMi = item.samReMi
                            keyObj.samReMi = that.Obj[item.id].samReCountMi
                        }
                        console.log(tempObj,keyObj)
                        for (const key in tempObj) {
                            if (Object.hasOwnProperty.call(tempObj, key)) {
                                if(tempObj[key] <= keyObj[key]){
                                    return false
                                }
                                
                            }
                        }
                        return true
                }
            }
        }
    },
    created() {
        this.getList()
        this.getAdditionInfo()
        this.getProjectList()
        this.getUnitList()
        // this.id && this.geFileByBiz(this.id)
    },
    watch: {
        fullscreen(val) {
            if (val === true) {
                this.tableHeight = 'calc(100vh - 258px)'
            } else {
                this.tableHeight = '300'
            }
        },
    },
    methods: {
        tableRowClassNameDefect({ row, rowIndex }) {
            if(row.samplingOne === '固定抽样'){
                return 'table-hidden-row'
            }
            if (row.isHighLight === true) {
                return 'rowHighLight' //若isHighLight为true，则使用“rowHighLight”样式
            } else {
                return ''
            }
        },
        caculateAsyncDefect(){
            // inspectionFlawList缺陷项一对多检验项
            let Obj = {}
			if(this.typeList && this.typeList.length && this.inspectionFlawList && this.inspectionFlawList.length){
				for (let s of this.inspectionFlawList) {
					let itemIdListCR = typeof s.itemClassIdCr == 'string' ? s.itemClassIdCr.split(',') : []
                    let itemIdListMA = typeof s.itemClassIdMa == 'string' ? s.itemClassIdMa.split(',') : []
                    let itemIdListMI = typeof s.itemClassIdMi == 'string' ? s.itemClassIdMi.split(',') : []
					Obj[s.id] = {}
					// Obj[s.id]['samAcCount'] = 0
                    Obj[s.id]['samReCountCr'] = itemIdListCR.length ? 0 : ''
                    Obj[s.id]['samReCountMa'] = itemIdListMA.length ? 0 : ''
                    Obj[s.id]['samReCountMi'] = itemIdListMI.length ? 0 : ''
                    let that = this
                    let caculateItem = function(item,samKey){
                        for (let i of item) {
                            for (let d of that.typeList) {
                                if(i == d.id && d.checkoutType == '数值'){
                                    let tempCheckoutList = JSON.parse(JSON.stringify(d.checkoutList))
                                    let CheckoutObj = {}

                                    for (const iterator of tempCheckoutList) {
                                        CheckoutObj[iterator.sampleCode] = iterator
                                    }
                                    for (const key in CheckoutObj) {
                                        if (CheckoutObj.hasOwnProperty.call(CheckoutObj, key)) {
                                            if(CheckoutObj[key].singleResult === 1 || CheckoutObj[key].singleResult === '1'){
                                                // Obj[s.id]['samAcCount'] += 1
                                            }else if (CheckoutObj[key].singleResult === 0 || CheckoutObj[key].singleResult === '0'){
                                                Obj[s.id][samKey] += 1
                                            }
                                        }
                                    }
                                }else if (i == d.id && d.checkoutType != '数值'){
                                    if(d.samplingOne == '固定抽样'){
                                        if(d.checkoutResult !== '' && d.checkoutResult !== null){
                                            Obj[s.id][samKey] += (d.samplingAmount - d.qualifiedNum)
                                        }
                                    }else if(d.samplingOne == 'GB/T2828.1-2012'){
                                        if(d.checkoutResult !== '' && d.checkoutResult !== null){
                                            Obj[s.id][samKey] += Number(d.resultValue)
                                        }
                                    }else{
                                        for (const j of d.checkoutList) {
                                            if(j.result === 1 || j.result === '1'){
                                                // Obj[s.id]['samAcCount'] += 1
                                            }else if (j.result === 0 || j.result === '0'){
                                                Obj[s.id][samKey] += 1
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    caculateItem(itemIdListCR,'samReCountCr')
                    caculateItem(itemIdListMA,'samReCountMa')
                    caculateItem(itemIdListMI,'samReCountMi')
				}
			}
            this.Obj = {...this.Obj,...Obj}
            console.log(this.Obj,'缺陷项统计结果！！！！！！！！！！！！！！！！')
        },
        showglb(){
            // var data={
            //     incomingId:this.id
            // }
            // listScanSampleCodeAPI(data).then(res=>{
                this.scanVisble=true
            // })
        },
      loadMore() {
        this.loadMoreLoading = true;
        // 模拟从服务器获取更多数据的过程
        setTimeout(() => {
          const start = (this.page - 1) * this.pageSize;
          const end = start + this.pageSize;
          console.log(this.currentItem.checkoutList)
          const dataSlice = this.currentItem.checkoutList.slice(start, end); // 从模拟数据中切片获取数据
          this.displayedCheckoutList = this.displayedCheckoutList.concat(dataSlice); // 追加数据到表格数据
          this.loadMoreLoading = false;
          if (end >= this.currentItem.checkoutList.length) {
            this.hasMore = false; // 已加载完所有数据
          }
          this.page++;
        }, 500); // 模拟延迟
      },
        formatCE_CLASS(e) {
            if (e) {
                let obj = this.dict.type.NYIQC_CE_CLASS.find((item) => {
                    return item.value === e
                })
                if (obj) {
                    return obj.label
                } else {
                    return ''
                }
            } else {
                return ''
            }
        },
        getItemFileById(id) {
            geFileByBiz({ bizId: id }).then((res) => {
                let itemFileList = []
                res.data.forEach((io) => {
                    if (io.bizType === 'UPLOAD_FILE_ITEM') {
                        itemFileList.push(io)
                    }
                })
                this.itemFileList = itemFileList
            })
        },
        async geFileByBiz(id) {
            await geFileByBiz({ bizId: this.isReuse === 1 ? JSON.parse(this.viewModel?.coaPic)?.inspectionId :id }).then((res) => {
                let otherList = []
                let trialBizTypeList=[]
                let coaBizTypeList=[]
                res.data.forEach((io) => {
                    if (io.bizType === 'UPLOAD_FILE_OTHERS') {
                        otherList.push(io)
                    }
                    if (io.bizType === 'onceTrialDoc') {
                        trialBizTypeList.push(io)
                    }
                    if (io.bizType === 'IncomingCoaBizType') {
                        coaBizTypeList.push(io)
                    }
                })
                this.otherList = otherList
                this.trialBizTypeList=trialBizTypeList
                this.coaBizTypeList=coaBizTypeList
            })
            await geFileByBiz({ bizId: this.isReuse === 1 ? JSON.parse(this.viewModel?.coaPic)?.extraId : this.viewModel.extraId }).then((rest) => {

                    rest.data.forEach((io) => {
                        if (io.bizType === 'IncomingCoaBizType') {
                            this.coaBizTypeList.unshift(io)
                        }
                    })
                })
        },
        changeFull() {
            const element = document.getElementById('fullscreen')
            if (this.fullscreen) {
                if (document.exitFullscreen) {
                    document.exitFullscreen()
                } else if (document.webkitCancelFullScreen) {
                    document.webkitCancelFullScreen()
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen()
                } else if (document.msExitFullscreen) {
                    document.msExitFullscreen()
                }
            } else {
                if (element.requestFullscreen) {
                    element.requestFullscreen()
                } else if (element.webkitRequestFullScreen) {
                    element.webkitRequestFullScreen()
                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen()
                } else if (element.msRequestFullscreen) {
                    // IE11
                    element.msRequestFullscreen()
                }
            }
            this.fullscreen = !this.fullscreen
        },
        getCheckoutResult(
            data,
            upperLimit,
            lowerLimit,
            gap,
            checkoutType,
            decimalPlace,
            samplingOne,
            samplingAmount,
            samRe
        ) {
            let checkoutValue = data ? data.split(',') : []
            let inspectionValues = []

            console.log(checkoutValue, 'checkoutValue=====')

            for (let i = 0; i < checkoutValue.length; i++) {
                let inspectionValue = checkoutValue[i]
                    ? parseFloat(checkoutValue[i])
                    : null
                let resultValue = null
                let resultType = null
                if (checkoutType === '布尔型') {
                    resultValue = inspectionValue
                    resultType =
                        resultValue === 'OK' ? 1 : resultValue === 'NA' ? 2 : 0
                } else {
                    resultValue = checkoutValue[i]
                        ? parseFloat(checkoutValue[i]) +
                          (gap && gap.length > 0 ? parseFloat(gap) : 0)
                        : null
                    if (
                        decimalPlace != '' &&
                        decimalPlace != null &&
                        decimalPlace != undefined
                    ) {
                        resultValue = resultValue
                            ? resultValue.toFixed(parseInt(decimalPlace))
                            : resultValue
                    } else {
                        resultValue = resultValue
                            ? resultValue.toFixed(2)
                            : resultValue
                    }

                    if (
                        resultValue > parseFloat(upperLimit) ||
                        resultValue < parseFloat(lowerLimit)
                    ) {
                        resultType = 0
                    }
                    if (
                        (resultValue < parseFloat(upperLimit) ||
                            resultValue == parseFloat(upperLimit)) &&
                        (resultValue > parseFloat(lowerLimit) ||
                            resultValue == parseFloat(lowerLimit))
                    ) {
                        resultType = 1
                    }
                }
                inspectionValues.push({
                    inspectionValue,
                    resultValue,
                    resultType,
                })
            }
            console.log(inspectionValues, 'inspectionValues=====')
            const resultTypes = inspectionValues.map((item) => item.resultType)
            if (checkoutValue.includes('')) {
                return ''
            }
            if (checkoutType === '布尔型' && checkoutValue.length > 0) {
                if (samplingOne === 'GB/T2828.1-2012') {
                    let tempValue =
                        parseInt(samplingAmount) - parseInt(checkoutValue[0])
                    return parseInt(tempValue) > parseInt(samRe) ||
                        parseInt(tempValue) === parseInt(samRe)
                        ? 0
                        : 1
                } else {
                    return checkoutValue == 'OK'
                        ? 1
                        : checkoutValue == 'NA'
                        ? 2
                        : 0
                }
            }
            if (resultTypes.length) {
                if (resultTypes.includes(0)) {
                    return 0
                } else {
                    return 1
                }
            }
        },
        getAdditionInfo() {
            incomingInfo(this.id).then((response) => {
                this.viewModel = response.data
                this.inspectionFlawList = response.data.inspectionFlawList
                let tableHeader = []
                let typeList = response.data.classList
                let samplingAmount = 0

                // this.samplingAmount = samplingAmount
              //是否是复用检验值的单子 0:否1:是
                this.isReuse = response.data.isReuse
                typeList.forEach((io) => {
                    io.checkoutResult = parseInt(io.checkoutResult)
                    // io.inspectorName = this.name
                    if (io.inspector) {
                        // io.checkoutResult = this.getCheckoutResult(
                        //     io.checkoutValue,
                        //     io.upperLimit,
                        //     io.lowerLimit,
                        //     io.gap,
                        //     io.checkoutType,
                        //     io.decimalPlace,
                        //     io.samplingOne,
                        //     io.samplingAmount,
                        //     io.samRe
                        // )
                    }
                    if (io.samplingAmount && io.checkoutType !== '布尔型') {
                        if (parseFloat(io.samplingAmount) > samplingAmount) {
                            samplingAmount = io.samplingAmount
                        }
                    }
                    if (io.checkoutType === '布尔型') {
                        io['value' + 0] = io.checkoutValue
                    } else {
                        for (let i = 0; i < io.samplingAmount; i++) {
                            let values = io.checkoutValue
                                ? io.checkoutValue.split(',')
                                : []
                            io['value' + i] = values[i]
                        }
                    }
                })
                for (let i = 0; i < samplingAmount; i++) {
                    tableHeader.push('结果值' + (i + 1))
                }
                this.tableHeader = tableHeader
                console.log(typeList, 'typeList========')
                this.typeList = typeList
                // this.getFlowByMaterialCode(this.viewModel.materialCode)
                this.loading = false
                this.caculateAsyncDefect()
            }).finally(e=>{
                this.geFileByBiz(this.id)
            })
        },
        getUnitList() {
            listCheckoutUnit().then((res) => {
                this.unitList = res.rows
            })
        },
        changeProject(e) {
            let obj = this.projectList.find((item) => {
                return item.projectName === e.row.projectName
            })
            this.typeList[e.$index].projectCode = obj.projectCode
            this.typeList[e.$index].projectId = obj.projectId
        },
        getProjectList() {
            listProject().then((res) => {
                this.projectList = res.rows
            })
        },
        supplierDataCallback(row) {
            this.viewModel.supplierNo = row.supplierNo
            this.viewModel.supplierType = row.supplierType
        },
        materialDataCallback(row) {
            this.viewModel.materialNo = row.materialNo
            this.viewModel.materialType = row.materialType
            this.viewModel.maturity = row.maturity
            this.viewModel.materialTypeName = row.materialTypeName
        },
        closeTab() {
            this.$router.push({ path: '/inspect/incoming' })
        },
        effectDateChange(e, scope) {
            if (parseInt(e) > 0) {
                this.typeList[scope.$index].endDate = this.getNewDay(
                    scope.row.approvalTime,
                    e
                )
            }
        },
        getNewDay(dateTemp, days) {
            var dateTemp = dateTemp.split('-')
            //转换为MM-DD-YYYY格式
            var nDate = new Date(
                dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]
            )
            var millSeconds = Math.abs(nDate) + days * 24 * 60 * 60 * 1000
            var rDate = new Date(millSeconds)
            var year = rDate.getFullYear()
            var month = rDate.getMonth() + 1
            if (month < 10) month = '0' + month
            var date = rDate.getDate()
            if (date < 10) date = '0' + date
            return year + '-' + month + '-' + date
        },
        fileChange(e) {
            console.log(e)
        },
        drawerClose() {
            this.drawer = false
          this.displayedCheckoutList=[]
          this.currentItem.checkoutList=[]
          this.hasMore = true
          this.page=1
          this.pageSize=200
        },
        /** 查询字典类型列表 */
        getList() {
            this.loading = true
            this.typeList = [
                {
                    approvalTime: '2022-05-19',
                    endDate: '',
                    measuringTool: null,
                },
            ]
            getNoticeList(this.queryParams).then((response) => {
                if (response.code == 200 && response.rows) {
                    //   this.typeList = response.rows;
                    this.total = response.total
                    this.loading = false
                }
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                dictId: undefined,
                dictName: undefined,
                dictType: undefined,
                status: '0',
                remark: undefined,
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.typeList.push({})
        },
        handleSelectTemplate() {
            this.templateVisible = true
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.dictId)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset()
            const dictId = row.dictId || this.ids
            getType(dictId).then((response) => {
                this.form = response.data
                this.open = true
                this.title = '修改字典类型'
            })
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs['additonForm'].validate((valid) => {
                if (valid) {
                    let typeList = [...this.typeList]
                    typeList.forEach((io, index) => {
                        let checkoutValues = []
                        for (let i = 0; i < io.samplingAmount; i++) {
                            checkoutValues.push(io['value' + i])
                        }
                        io.checkoutValue = checkoutValues.join(',')
                        console.log(io.checkoutValue)
                    })
                    let submitData = { ...this.viewModel, classList: typeList }
                    console.log(JSON.stringify(submitData))
                    getCollection(submitData).then((response) => {
                        this.$modal.msgSuccess('提交成功!')
                        this.$router.push({ path: '/inspect/incoming' })
                    })
                } else {
                    console.log('error submit!!')
                    return false
                }
            })
        },
        /** 发起检验提交 */
        submitAddForm: function () {
            this.$modal.msgSuccess('发起成功!')
            this.addInspection = false
        },

        /** 删除按钮操作 */
        handleDelete(row) {
            if (this.typeList.length === 1) {
                this.$modal.msgWarning('请至少保留一条检验项!')
                return
            }
            this.typeList.splice(row.$index, 1)
        },
        /** 查看按钮操作 */
        handleView(row) {
            this.form = row
            this.viewInspectionExemption = true
            //   if(row.hasRead == 0){
            //     readNotice(row.noticeId).then(res=>{
            //       if(res.code == 200){
            //         this.handleQuery()
            //       }
            //     })
            //   }
        },
        /** 编辑按钮操作 */
        handleEdit(scope) {
            let currentItem = JSON.parse(JSON.stringify(scope.row))
            this.comprehensiveResults = ''
            if (!currentItem.inspector) {
                // currentItem.inspectorName = this.name
                currentItem.inspector = this.userId
            } else {
                this.currentItem.inspectorName = currentItem.inspectorName
                this.currentItem.inspector = currentItem.inspector
            }

            console.log(currentItem, 'currentItem')
            currentItem.index = scope.$index
            let checkoutValue = currentItem.checkoutValue
                ? currentItem.checkoutValue.split(',')
                : currentItem.checkoutList?.map(i=>i.checkoutValue)

            let resultValue = void 0;
            let result = void 0;
            if(!currentItem.resultValue) resultValue = currentItem.checkoutList?.map(i=>i.resultValue)
            if(!currentItem.result) result = currentItem.checkoutList?.map(i=>i.result)

            let inspectionValues = []
            if (scope.row.checkoutType === '布尔型') for (let i = 0; i < currentItem.samplingAmount; i++) {
                let inspectionValue = checkoutValue[i] ? checkoutValue[i] : ''

                let resultValue = resultValue??''
                let resultType = result??''
                if (scope.row.checkoutType === '布尔型') {
                    if (scope.row.samplingOne === 'GB/T2828.1-2012') {
                        resultValue =
                            parseInt(scope.row.samplingAmount) -
                            parseInt(inspectionValue)
                        if (
                            inspectionValue === '' ||
                            inspectionValue === null ||
                            inspectionValue === undefined
                        ) {
                            resultValue = null
                            resultType = null
                        } else if (
                            resultValue > parseInt(scope.row.samRe) ||
                            resultValue === parseInt(scope.row.samRe)
                        ) {
                            resultType = 0
                        } else {
                            resultType = 1
                        }
                    } else if (scope.row.samplingOne === 'GB/T2828.2-2008') {
                        resultValue =
                            parseInt(scope.row.samplingAmount) -
                            parseInt(inspectionValue)
                        if (
                            inspectionValue === '' ||
                            inspectionValue === null ||
                            inspectionValue === undefined
                        ) {
                            resultValue = null
                            resultType = null
                        } else if (resultValue > parseInt(scope.row.samAc)) {
                            resultType = 0
                        } else {
                            resultType = 1
                        }
                    } else {
                        resultValue = inspectionValue
                        if (resultValue == '0') {
                            resultType = 1
                        } else if (resultValue == '2') {
                            resultType = 2
                        } else if (resultValue == '1') {
                            resultType = 0
                        } else {
                            resultType = null
                        }
                    }
                } else {
                    resultValue = checkoutValue[i]
                        ? parseFloat(
                              checkoutValue[i] && checkoutValue[i].length > 0
                                  ? parseFloat(checkoutValue[i])
                                  : checkoutValue[i] + currentItem.gap &&
                                    currentItem.gap.length > 0
                                  ? parseFloat(currentItem.gap)
                                  : currentItem.gap
                          )
                        : null
                    if (
                        currentItem.decimalPlace != '' &&
                        currentItem.decimalPlace != null &&
                        currentItem.decimalPlace != undefined
                    ) {
                        resultValue = resultValue
                            ? resultValue.toFixed(
                                  parseInt(currentItem.decimalPlace)
                              )
                            : resultValue
                    } else {
                        resultValue = resultValue
                            ? resultValue.toFixed(2)
                            : resultValue
                    }
                    if (
                        resultValue > parseFloat(currentItem.upperLimit) ||
                        resultValue < parseFloat(currentItem.lowerLimit)
                    ) {
                        resultType = 0
                        if (checkoutValue.length > 0) {
                            this.comprehensiveResults = '不合格'
                        }
                    }
                    if (
                        (resultValue < parseFloat(currentItem.upperLimit) ||
                            resultValue ==
                                parseFloat(currentItem.upperLimit)) &&
                        (resultValue > parseFloat(currentItem.lowerLimit) ||
                            resultValue == parseFloat(currentItem.lowerLimit))
                    ) {
                        resultType = 1
                        if (checkoutValue.length > 0) {
                            this.comprehensiveResults = '合格'
                        }
                    }
                }

                if (scope.row.checkoutType === '布尔型' && i > 0) {
                    continue
                }
                inspectionValues.push({
                    inspectionValue,
                    resultValue,
                    resultType,
                })
            }
            console.log(inspectionValues)
            if (checkoutValue.includes('') || checkoutValue.includes(null)) {
                this.comprehensiveResults = ''
            }
            if (currentItem.checkoutResult == '1') {
                this.comprehensiveResults = '合格'
            }
            if (currentItem.checkoutResult == '2') {
                this.comprehensiveResults = 'NA'
            }
            if (currentItem.checkoutResult == '0') {
                this.comprehensiveResults = '不合格'
            }
            if (currentItem.checkoutResult === '') {
                this.comprehensiveResults = ''
            }

            // 样本检验项
        if( scope.row.checkoutType === '数值'){
            let checkoutList = [];
            if(Array.isArray(currentItem.checkoutList) && currentItem.checkoutList.length > 0){
                let sampleCodeEnum = {}
                let samplingSort = []
                currentItem.checkoutList.forEach(i=>{
                    if(i.sampleCode) {
                        if(samplingSort.indexOf(i.sampleCode) == -1) samplingSort.push(i.sampleCode) 
                        if(Array.isArray(sampleCodeEnum[i.sampleCode])){
                            sampleCodeEnum[i.sampleCode].push(i)
                        }else {
                            sampleCodeEnum[i.sampleCode] = [i]
                        }
                    }
                })
                console.log(samplingSort,sampleCodeEnum,'保证顺序1')
                for (const iterator of samplingSort) {
                    for (const key in sampleCodeEnum) {
                        if (Object.hasOwnProperty.call(sampleCodeEnum, key)) {
                            if(key === iterator){
                                checkoutList.push({
                                    sampleCode: key,
                                    checkoutItemList: sampleCodeEnum[key]
                                })
                            }
                        }
                    }
                }
                console.log(checkoutList,'保证顺序2')
                if(checkoutList.length != currentItem.samplingAmount){
                    let applyArr = Array.from({length: currentItem.samplingAmount - checkoutList.length}, () =>
                     (
                        {
                            sampleCode:undefined,
                            checkoutItemList: [new CheckoutItem()]
                        }
                     ))
                    console.log('拼接数组',applyArr)
                    checkoutList = checkoutList.concat(applyArr)

                    console.log('拼接数组',checkoutList)
                }
            }else {
                for (let i = 0; i < currentItem.samplingAmount; i++) {
                    checkoutList.push(
                        {
                            sampleCode:undefined,
                            checkoutItemList: [new CheckoutItem()]
                        }
                    )
                }
            }
            currentItem.checkoutList = checkoutList
        }

            currentItem.flawProjectName = scope.row.flawProjectName
                ? scope.row.flawProjectName.split(';')
                : scope.row.flawProjectName
            currentItem.inspectionValues = inspectionValues
            console.log(currentItem.inspectionValues)
            this.currentItem = currentItem
            this.rowId = scope.row.id
            this.getItemFileById(this.rowId)
            this.drawer = true
            // this.judgeQualifid()
          this.loadMore()
        },
        /** 关闭抽屉操作 */
        handleClose(row) {
            this.drawer = false
          this.displayedCheckoutList=[]
          this.currentItem.checkoutList=[]
          this.hasMore = true
          this.page=1
          this.pageSize=200
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(
                'system/dict/type/export',
                {
                    ...this.queryParams,
                },
                `type_${new Date().getTime()}.xlsx`
            )
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
            })
        },
    },
}
</script>
<style lang="scss" scoped>
.load-more-container {
  bottom: 0;
  background-color: #fff;
  z-index: 1;
  padding: 10px;
  text-align: center;
}
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
.header-left {
    float: left;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    line-height: 40px;
    display: flex;
    justify-content: center;
}
.header-right {
    float: right;
}
.container-header {
    float: left;
    width: 100%;
    border-bottom: 1px solid #ededf2;
    padding-left: 12px;
}
.container-table {
    float: left;
    margin-top: 6px;
    width: 100%;
    max-height: calc(100vh - 200px);
    overflow: auto;
}
.mb8 {
    display: flex;
    flex-wrap: wrap;
    margin-top: 6px;
    width: 100%;
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.hign-line {
    position: relative;
    left: -8px;
    top: 14px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #0b7be3;
    float: left;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}
.submit-footer {
    height: 52px;
    background: #ffffff;
    box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px 4px 0px 0px;
    position: fixed;
    z-index: 9;
    bottom: 0px;
    width: 100%;
    left: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.samplingPercent {
    position: absolute;
    z-index: 9;
    right: 20px;
}
::v-deep .el-card {
    padding-top: 0px;
}
.app-detail {
    max-height: calc(100vh - 180px);
    overflow: auto;
}
.result-tag-red {
    width: 36px;
    height: 18px;
    font-size: 12px;
    font-weight: 400;
    color: #eb5648;
    background: rgba(235, 86, 72, 0.08);
    line-height: 18px;
    border-radius: 2px;
}
.result-tag-green {
    width: 40px;
    height: 20px;
    font-size: 12px;
    font-weight: 400;
    color: #20b09f;
    line-height: 18px;
    background: rgba(32, 176, 159, 0.08);
    border-radius: 2px;
}

.result-tag-yellow {
    width: 40px;
    height: 20px;
    font-size: 12px;
    font-weight: 400;
    color: #dbcd0c;
    line-height: 18px;
    background: rgba(236, 175, 7, 0.08);
    border-radius: 2px;
}
.header-right {
    float: right;
}
::v-deep .table-hidden-row{
    display:none;
}
</style>
